<?php
	include_once("Database.inc");
	include_once("Province.inc");
	
class District {
	
	public $id;
	public $name;
	public $province;
	
	/*
	 * Obtains all districts for the specified province.
	 */
	public static function getAllDistricts($province) {
		$d = array();
		
		$query = $GLOBALS["DB"] -> doQuery("SELECT DISTRICTCODE, DISTRICTNAME, PROVINCECODE FROM DISTRICTS ".
											"WHERE PROVINCECODE='$province' ORDER BY DISTRICTCODE" );
		
		while ($row = mssql_fetch_array($query)) {
			array_push($d, District::getDistrictFromArray($row));
		}
		
		return $d;
	}
	
	public static function getDistrict($id) {
                $query = $GLOBALS["DB"] -> doQuery("SELECT DISTRICTCODE, DISTRICTNAME, PROVINCECODE FROM DISTRICTS ".
											"WHERE DISTRICTCODE='$id'");
			
		if ($row = mssql_fetch_array($query)) {
			return District::getDistrictFromArray($row);	
		}
	}
	
	protected static function getDistrictFromArray($array) {
		$d = new District();
		
		$d->id = $array[0];
		$d->name = $array[1];
		$d->province = $array[2];
		
		return $d;
	}
	
	
}